<template>
  <el-form :inline="true" :model="formInline" class="form-inline">
    <el-form-item label="管线类型：">
      <el-select v-model="formInline.type" placeholder="--请选择--">
        <el-option
          v-for="item in lineArray"
          :key="item.type"
          :label="item.type"
          :value="item.type"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="所属单位：">
      <el-input v-model="formInline.unit" placeholder="--请输入--"></el-input>
    </el-form-item>
    <el-form-item label="竣工日期：">
      <el-date-picker
        v-model="date"
        type="daterange"
        value-format="YYYY-MM-DD "
        start-placeholder="开始时间"
        range-separator="~"
        end-placeholder="结束时间"
        @change="change"
        size="small"
      />
    </el-form-item>
    <el-form-item class="btns">
      <el-button type="primary" @click="onSubmit">查询</el-button>
      <el-button type="success" class="m-left" @click="onClear">清空</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup>
import { ref, reactive, defineEmits } from 'vue'
import { pipeTypelist } from '@/api/back'

const date = ref([])
const formInline = reactive({
  type: '',
  unit: '',
  startDate: '',
  endDate: ''
})

const change = (res) => {
  if (res) {
    formInline.startDate = res[0]
    formInline.endDate = res[1]
  } else {
    formInline.startDate = ''
    formInline.endDate = ''
  }
}
const lineArray = ref([])
const getListData = async () => {
  lineArray.value = await pipeTypelist()
}
getListData()

const emits = defineEmits(['onSearch'])

const onSubmit = () => {
  emits('onSearch', formInline)
}

const onClear = () => {
  formInline.type = ''
  formInline.unit = ''
  formInline.endDate = ''
  formInline.startDate = ''
  date.value = []
  emits('onSearch', formInline)
}
</script>
<style lang="scss" scoped>
.form-inline {
  width: 100%;
  position: relative;
  display: flex;
  column-gap: 20px;
  padding-bottom: 33px;
  // margin-top: -5px;
  .btns {
    position: absolute;
    right: 0;
    top: 4px;
    .m-left {
      margin-left: 20px;
    }
  }
}
</style>
